//
//  ZLWelcomeController.swift
//  新浪微博
//
//  Created by 朱玉龙 on 9/27/16.
//  Copyright © 2016 朱玉龙. All rights reserved.
//

import UIKit
import SDWebImage

private let bottonMargin = 120

class ZLWelcomeController: UIViewController {

   
    
    override func viewDidLoad() {
        super.viewDidLoad()

    view.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        
        setMyUI()
    }
    
    
   override func viewDidAppear(_ animated: Bool) {
    
    animation()
    
    }
    
    private func animation() {
        
        let offsetY = Int(UIScreen.main.bounds.height) - bottonMargin - 85
        
        iconIamgeView.snp.updateConstraints { (make) in
            
            make.bottom.equalTo(self.view).offset(-offsetY)
        }
        
        
        UIView.animate(withDuration: 1.2, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 8, options: [], animations: {
            
            self.view.layoutIfNeeded()
            
            }) { (_) in
                
            UIView.animate(withDuration: 0.2, delay: 0, options: [], animations: {
                
                self.titleLabel.alpha = 1
                
                }, completion: { (_) in
                    
                   NotificationCenter.default.post(name: NSNotification.Name.init(kChangeRootController), object: nil)
            })
        }
        
    }
    
    private func setMyUI() {
    
        
        view.addSubview(iconIamgeView)
        view.addSubview(titleLabel)
        
        //设置约束,添加控件
        iconIamgeView.snp.makeConstraints { (make) in
        
            make.height.width.equalTo(85)
            
            make.centerX.equalTo(self.view)
            
            make.bottom.equalTo(self.view).offset(-bottonMargin)
            
        }
        
        iconIamgeView.sd_setImage(with: ZLOAthorViewModel.shareOAthor.iconURL)
        
        titleLabel.snp.makeConstraints { (make) in
            
            make.centerX.equalTo(iconIamgeView)
        
            make.top.equalTo(iconIamgeView.snp.bottom).offset(20)
        }
    
    }
//懒加载控件
  private  lazy var iconIamgeView:UIImageView = {
        
       let iv = UIImageView()
        
        iv.layer.cornerRadius = 42
        
        iv.layer.masksToBounds = true
        
        iv.layer.borderWidth = 2
        
        iv.layer.borderColor = UIColor.orange.cgColor
        
        return iv
    }()
    
    private lazy var titleLabel:UILabel = {
        
        let label = UILabel(title: "欢迎回来", color: UIColor.darkGray, fontSize: 15)
        
        label.textAlignment = .center
        
        label.alpha = 0
        
        return label
    }()
    
    
}
